# lianjie.py (PyMySQL 版本)

import pymysql
from pymysql import Error

def connect_mysql():
    try:
        conn = pymysql.connect(
            host='localhost',
            user='root',
            password='@Hu051005',
            port=3306,
            charset='utf8mb4',
            database='xm',  # 确保数据库名称正确
            cursorclass=pymysql.cursors.DictCursor
        )
        print("✅ 成功连接! MySQL版本:", conn.get_server_info())
        return conn
    except Error as e:
        print("❌ 连接失败:", e)
        return None

def getConnect():
    # 调用真正的连接函数
    return connect_mysql()  # 关键修正点！

# 测试用例（可删除）
if __name__ == "__main__":
    conn = getConnect()  # 调用修正后的函数
    if conn:
        with conn.cursor() as cursor:
            cursor.execute("SHOW TABLES")
            print("📋 表列表:", [t for t in cursor.fetchall()])
        conn.close()